{block name=body} {* Define the function *} {function name=options_list level=0} {foreach $opts as $opt}
{if $level eq 0}
<optgroup label="{$opt.value}">
{else}
<option value="{$opt.id}" {if $selected eq $opt.id}selected="selected" {/if}>{$opt.value}</option>
{/if} {if count($opt.subs) > 0} {call name=options_list opts=$opt.subs level=$level+1 } {/if} {/foreach} {/function}
<div class="container content hidden-xs">
    <div class="row">
        <div class="col-sm-12">
            <!--{include file='breadcrumbs.tpl'}
            <h2 class="title"></h2>-->
        </div>
        <div class="col-sm-12">
            {$listing_content1}
        </div>
    </div>
    <!-- /.row -->
</div>
<div id="enroltrialhead">
    <div class="container">
        <div class="row">
            <div class="col-sm-12 text-center">
                <span>{$lang.login.loginregister}
            </span></div>
        </div>
    </div>
</div>
<div id="enroltrialmain">
    <div class="container">
        <div class="row">
            <div class="col-sm-12">
                <!-- LOGIN SECTION  -->
                <div class="col-sm-4 col-sm-offset-1" id="login">
                    <div class="col-sm-12">
                        <div class="row">
                            <h3>{$lang.login.exist}</h3>
                        </div>
                        <div id="login">
                            <form class="form-horizontal" id="login-form" data-attr-id="login-form" role="form" accept-charset="UTF-8" action="" method="post">
                                <input type="hidden" value="login" name="action" id="action" />
                                <input type="hidden" value="{$redirect}" name="redirect" class="redirect" />
                                <input type="hidden" name="formToken" id="formToken" value="{$token}" />
                                <div class="row">
                                    <div class="form-group">
                                        <label for="username">{$lang.login.username}</label>
                                        <input type="text" value="{if $post}{$post.email}{/if}" class="form-control username" id="username" name="username" required>
                                        <span class="help-block"></span>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="form-group">
                                        <label for="password">{$lang.login.password}</label>
                                        <input class="form-control" type="password" id="password1" name="pass" autocomplete="off" required/>
                                        <a class="showhide" style="line-height: 34px;position: absolute;right: 20px;" href="javascript:void(0);" onclick="if($(this).html() == '显示'){ $(this).closest('div').find('input[name=pass]').get(0).type='text';$(this).html('隐藏'); }else{ $(this).closest('div').find('input[name=pass]').get(0).type='password';$(this).html('显示'); }">显示</a>
                                        <span class="help-block"></span>
                                        <span class="form-help-block"><a href="javascript:void(0)" onclick="$('#reset-pass').show('slow');">{$lang.login.forget}</a></span>
                                    </div>
                                </div>
                                <div class="col-sm-12 error-alert" style="display:none;">
                                    <div class="alert alert-danger fade in ">
                                        <button class="close" aria-hidden="true" type="button" onclick="$(this).closest('.error-alert').fadeOut('slow');">&times;</button>
                                        <strong></strong>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="form-group">
                                        <button type="submit" class="enquire">{$lang.login.login}</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div id="reset-pass" style="display:none;">
                            <div class="row">
                                <h3>{$lang.login.reset_title}</h3></div>
                            <form class="form-horizontal" id="reset-pass-form" data-attr-id="reset-pass-form" role="form" accept-charset="UTF-8" action="" method="post">
                                <input type="hidden" value="resetPassword" name="action" id="action" />
                                <input type="hidden" name="formToken" id="formToken" value="{$token}" />
                                <div class="row">
                                    <div class="form-group">
                                        <label for="email">{$lang.login.email}</label>
                                        <input type="email" value="{if $post}{$post.email}{/if}" class="form-control" id="reset-email" name="email" required>
                                        <span class="help-block"></span>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="form-group">
                                        <button type="submit" class="enquire">{$lang.login.reset_title}</button>
                                    </div>
                                </div>
                                <div class="col-sm-12 error-alert" style="display:none;">
                                    <div class="alert alert-danger fade in ">
                                        <button class="close" aria-hidden="true" type="button" onclick="$(this).closest('.error-alert').fadeOut('slow');">&times;</button>
                                        <strong></strong>
                                    </div>
                                </div>
                                <div class="col-sm-12 success-alert" style="display:none;">
                                    <div class="alert alert-success fade in ">
                                        <button class="close" aria-hidden="true" type="button" onclick="$(this).closest('.success-alert').fadeOut('slow');">&times;</button>
                                        <strong></strong>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
                <!-- RESET PASSWORD SECTION - Hidden by default -->
                <!-- REGISTER SECTION - Hidden by default -->
                <div class="col-sm-4 col-sm-offset-1" id="register">
                    <div class="col-sm-12">
                        <div class="row">
                            <h3>{$lang.login.join}</h3></div>
                        <form class="form-horizontal" id="register-form" data-attr-id="register-form" role="form" accept-charset="UTF-8" action="" method="post">
                            <input type="hidden" value="create" name="action" id="action" />
                            <input type="hidden" value="{$redirect}" name="redirect" class="redirect" />
                            <input type="hidden" name="formToken" id="formToken" value="{$token}" />
                            <div class="form-group">
                                <label for="gname">{$lang.login.name}</label>
                                <input type="text" value="{if $post}{$post.gname}{/if}" class="form-control" id="gname" name="gname" required>
                                <span class="help-block"></span>
                            </div>
                            <div class="form-group">
                                <label for="phone">{$lang.login.phone}</label>
                                <input type="text" value="{if $post}{$post.phone}{/if}" class="form-control phone" id="phone" name="phone" required>
                                <a class="smscode btn" style="line-height: 34px;position: absolute;right: 0px;top:278px;" href="javascript:void(0);" id="getSmsCode">获取验证码</a>
                                <span class="help-block"></span>
                            </div>
                            <div class="form-group">
                                <label for="sign">{$lang.login.sign}</label>
                                <input type="text" value="{if $post}{$post.sign}{/if}" class="form-control" id="sign" name="sign" required>
                                <span class="help-block"></span>
                            </div>
                            <!-- <div class="form-group">
                                <label for="email">{$lang.login.email}</label>
                                <input type="email" value="{if $post}{$post.email}{/if}" class="form-control" id="reg-email" name="email" required>
                                <span class="help-block"></span>
                            </div> -->
                            <div class="form-group">
                                <label for="password">{$lang.login.password}</label>
                                <input type="password" value="" class="form-control" id="password" name="password" autocomplete="off" required>
                                <a class="showhide" style="line-height: 34px;position: absolute;right: 20px;" href="javascript:void(0);" onclick="if($(this).html() == '显示'){ $(this).closest('div').find('input[name=password]').get(0).type='text';$(this).html('隐藏'); }else{ $(this).closest('div').find('input[name=password]').get(0).type='password';$(this).html('显示'); }">显示</a>
                                <span class="help-block"></span>
                            </div>
                            <div class="form-group">
                                <label for="hearabout">{$lang.contact.hear}</label>
                                <select id="hearabout" required tabindex="0" class="required" name="user_hearabout">
                                    <option value="">{$lang.contact.select}</option>
                                    {if $post}{assign var='selected' value=$post.hearabout}{else}{assign var='selected' value=$user.user_hearabout}{/if} {call name=options_list opts=$hearabout selected=$selected}
                                </select>
                            </div>
                            <div class="col-sm-12 error-alert" style="display:none;">
                                <div class="alert alert-danger fade in ">
                                    <button class="close" aria-hidden="true" type="button" onclick="$(this).closest('.error-alert').fadeOut('slow');">&times;</button>
                                    <strong></strong>
                                </div>
                            </div>
                            <div class="form-group">
                                <button id="signup-btn" type="submit" class="enquire">{$lang.login.register}</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<br>
<br> 
{/block}
{* Place additional javascript here so that it runs after General JS includes *}
{block name=tail}
{literal}
<script type="text/javascript">
$(function() {
    $('select').selectBoxIt();
});
$(document).ready(function() {
    $.validator.addMethod("phone", function(value) {
        var phone = /^1[34578]\d{9}$/;
        return phone.test(value);
    }, '手机号错误');
    $.validator.addMethod("username", function(value) {
        var phone = /^1[34578]\d{9}$/;
        var email = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
        return phone.test(value) || email.test(value);
    }, '手机号或邮箱错误');
    $('#login-form').validate({
        errorPlacement:function(error, element){
            console.log(element);
            error.appendTo(element.parent().children('.help-block'));
        }
    });
    $('#register-form').validate();
    $('#reset-pass-form').validate({
        onkeyup: false,
        onclick: false
    });

    $("#getSmsCode").click(function () {
        console.log(11);
        //验证手机号
        if($("#register-form").validate().element($("#phone"))){
            $("#getSmsCode").attr("disabled", "disabled");
            requestSmsCode($("#phone").val());
        }
    });

    function requestSmsCode(mobile){
        $.ajax({
            type: "POST",
            url: "/process/sms",
            cache: false,
            data: "phone="+$("#phone").val(),
            dataType: "json",
            success: function(data) {
                if(data.success){
                    timeKeeper($("#getSmsCode"));
                }else{
                    $('#register-form').find('.error-alert').find('strong').html(data.error?'':'发送验证码失败');
                    $('#register-form').find('.error-alert').fadeIn('slow');
                }
            },
            error: function() {
                $("#getSmsCode").removeAttr("disabled");
            }
        });
    }

    function timeKeeper(smscodeitem) {
        //time to wating for next sms sending
        var timeSpan = 60;
        //lock
        smscodeitem.attr("disabled", "disabled");
        smscodeitem.text(timeSpan.toString() + "s后重新发送");
        //smscodeitem.addClass("invalid");
        interval = setInterval(function () {
            smscodeitem.text(timeSpan.toString() + "s后重新发送");
            timeSpan = timeSpan - 1;
            if (timeSpan == 0) {
                //unlock
                smscodeitem.text("获取验证码");
                smscodeitem.removeAttr("disabled");
                clearInterval(interval)
            }
        }, 1000);
    };
});

function redirectWin(url) {
    window.location.replace(url);
}
</script>
{/literal}
{/block}
